# 用requests框架 主要针对 反爬+实战
import json

import requests

page = 3
limit = 20
url = f"https://m.douban.com/rexxar/api/v2/subject/recent_hot/tv?start={(page - 1) * limit}&limit={limit}&category=tv&type=tv"
print("请求的url--->", url)

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36",
    "referer": "https://movie.douban.com/tv/?support_type=tv&is_all=false&category=tv&type=tv",
}

resp = requests.get(url, headers=headers)
resp.encoding = 'utf-8'
print("打印请求的 headers--->", resp.request.headers)
jsonx = resp.json()
# print(resp.status_code)

# 记得关闭
resp.close()

# formatted_json = json.dumps(jsonx, indent=4, ensure_ascii=False)  # 格式化json
formatted_json = json.dumps(jsonx, ensure_ascii=False)
print(formatted_json)
